<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class Goods extends Model
{


    

    // 表名
    protected $name = 'goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';
    // 追加属性
    protected $append = [
    ];
    public function getThumbnailImageAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['thumbnail_image']) ? $data['thumbnail_image'] : '');
        return get_app_image_url($value);
    }
    public function getGoodsImagesAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['goods_images']) ? $data['goods_images'] : '');
        $value=explode(',',$value);
        foreach ($value as $k=>&$v){
            $v=get_app_image_url($v);
        }
        return $value;
    }

    public function category3()
    {
        return $this->belongsTo('GoodsCategory', 'category3_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function category2()
    {
        return $this->belongsTo('GoodsCategory', 'category2_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function category1()
    {
        return $this->belongsTo('GoodsCategory', 'category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function brand()
    {
        return $this->belongsTo('Brand', 'brand_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
